//
//  leadViewController.m
//  road_1.1
//
//  Created by dllo on 15/10/31.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "leadViewController.h"

@interface leadViewController ()<UIScrollViewDelegate>
@property(nonatomic, retain)UIScrollView *scrollView;
@property(nonatomic, retain) UIPageControl *page;
@end

@implementation leadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    self.scrollView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.scrollView];
    [_scrollView release];
    
    self.scrollView.contentSize = CGSizeMake(3 * self.view.frame.size.width, 0);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.contentOffset = CGPointMake(0 , 0);
    self.scrollView.delegate = self;

    
    for (NSInteger i = 1; i < 4; i++) {
        NSString *imageName = [NSString stringWithFormat:@"leader%ld.jpg", i];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((i - 1) * self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
        imageView.image = [UIImage imageNamed:imageName];
        [self.scrollView addSubview:imageView];
        [imageView release];
    }
    
    self.scrollView.bounces = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    
    
    // 创建一个pageControl
    self.page = [[UIPageControl alloc] initWithFrame:CGRectMake(100, 635, 200, 40)];
    [self.view addSubview:self.page];

    self.page.numberOfPages = 3;  // 点的个数
    self.page.currentPageIndicatorTintColor = [UIColor blackColor];
    self.page.pageIndicatorTintColor = [UIColor grayColor];
    [_page release];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"进入应用" forState:(UIControlStateNormal)];
    button.backgroundColor = [UIColor whiteColor];
    button.frame = CGRectMake(self.view.frame.size.width * 2 + 143, 600, 80, 40);
    [self.scrollView addSubview:button];
    [button addTarget:self action:@selector(clickbutton:) forControlEvents:(UIControlEventTouchUpInside)];
    
    
}
- (void)clickbutton:(UIButton *)button{


    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
- (void)pageAction:(UIPageControl *)page{
    
    [self.scrollView setContentOffset:CGPointMake((page.currentPage + 1) * self.view.frame.size.width, 0) animated:YES];
}
// 滑动结束, 触发的协议方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    self.page.currentPage = scrollView.contentOffset.x / self.view.frame.size.width;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
